package com.ylr.demo2.JsonView;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * @ClassName User
 * @Description TODO
 * @Author 11
 * @Date 2021/6/19 15:00
 * @Version 1.0
 * SpringMVC注解之@JsonView
 * 使用步骤：
 *
 * 第一步：使用接口来声明多个视图
 *
 * 第二步：在值对象的get方法上指定视图
 *
 * 第三步：在Controller方法上指定视图
 */
public class User {
    public interface UserSimpleView{};

    public interface FieldSimpleView{};

    public interface UserDetailView extends UserSimpleView{};

    private int id;

    private String username;
    private String password;
    @JsonView({FieldSimpleView.class,UserSimpleView.class})
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @JsonView(UserSimpleView.class)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @JsonView(UserSimpleView.class)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    @JsonView(UserDetailView.class)
    public String getPassword() {
        return password;
    }


    public void setPassword(String password) {
        this.password = password;
    }

    public User(int id, String username, String password, int age) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", age=" + age +
                '}';
    }
}
